package org.itzheng.ui;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.itzheng.and.activity.ui.view.AttachView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * Title:<br>
 * Description: <br>
 *
 * @email ItZheng@ZoHo.com
 * Created by itzheng on 2020-5-9.
 */
public class GrayView extends AttachView {
    /**
     * 使用View实例化，最终将显示到最近的 FrameLayout 上
     *
     * @param view
     * @return
     */
    public static GrayView newInstance(Context context, View view) {
        GrayView mView = new GrayView(context);
        mView.setAttachView(view);
        return mView;
    }

    /**
     * 使用 Activity 实例化，最终将显示到 Activity 最外层
     *
     * @param activity
     * @return
     */
    public static GrayView newInstance(Activity activity) {
        if (activity == null || activity.isFinishing()) {
            //如果Activity结束就不创建了
            return null;
        }
        return newInstance(activity, (ViewGroup) activity.getWindow().getDecorView());
    }

    public GrayView(@NonNull Context context) {
        super(context);
    }

    public GrayView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public GrayView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected View onCreateView() {
        View view = new TextView(getContext());
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        view.setBackgroundColor(Color.parseColor("#33121100"));
        return view;
    }
}
